'use strict';
const dayjs = require("dayjs");
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { INTEGER, DATE, TINYINT } = app.Sequelize;
    const Cart = app.model.define(
        'Cart',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            user_id: INTEGER,
            product_id: INTEGER,
            checked: {type: TINYINT, defaultValue: 0},
            count: {type: INTEGER, defaultValue: 1},
            status: {type: TINYINT, defaultValue: 1},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'cart',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );

    Cart.associate = function () {
        app.model.Business.Cart.belongsTo(app.model.Business.User, {as: 'user', foreignKey: 'user_id'});
        app.model.Business.Cart.belongsTo(app.model.Business.Product, {as: 'product', foreignKey: 'product_id'});
    }
    return Cart;
};
